<%-- 
    Document   : materiais
    Created on : 09/03/2014, 01:11:36
    Author     : jordan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="./css/cliente.css" type="text/css" />
        <title>Materiais</title>
    </head>
    <body>
        <c:import url="menu.jsp" />
        <c:set var="tipoUsuario" value=
            "<%=(
                session.getAttribute("tipoUsuario")
            )%>"/>
        <c:set var="id" value=
            "<%=(
                session.getAttribute("id")
            )%>"/>
        <c:if test="${id==null}">
            <c:redirect url="index.jsp?error=14,W;${id}"/>
        </c:if>
        <c:if test="${tipoUsuario!='3'}">
            <c:redirect url="index.jsp#${id}#"/>
        </c:if>
        <c:if test="${param.retorna=='retorna'}">
            <c:redirect url="index.jsp"/>
        </c:if>
        
        <c:set var="operacao" value="${param.insere}${param.consulta}${param.altera}${param.exclui}"/>
        <c:set var="habilitaEdicao" value=""/>
        <c:set var="textoBotao" value="Salvar Dados"/>
        <c:if test="${operacao == 'consulta'||operacao=='exclui'}">
            <c:set var="habilitaEdicao" value="readonly='readonly'"/>
            <c:set var="textoBotao" value="Retornar"/>
        </c:if>
        
        <c:if test="${operacao!='insere'}">
            <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
                url="jdbc:mysql://localhost/coleta_seletiva"
                user="root" password=""/>
            <sql:query dataSource="${snapshot}" var="result">
                SELECT * from material where id=?;
                <sql:param value="${param.id}"/>
            </sql:query>
            <c:if test="${result.rowCount>0}">
                <c:if test="${result.rows[0].toxico}">
                    <c:set var="checkedToxico" value="checked='checked'"/>
                 </c:if>
            </c:if>
        </c:if>
        
        <h1>Materiais - ${operacao}</h1>
        <form action="confirmacaoMateriais.jsp" method="post">
            <input type="hidden" name="operacao" value="${param.insere}${param.consulta}${param.altera}${param.exclui}"/>
          <fieldset style=" border: none; width: 85%">
            <table style="width: 80%">
                <tr>
                    <td align="right" style="width: 50%">
                        <button name="retorna" value="retorna">Retornar</button>
                    </td>
                </tr>
            </table>
          </fieldset>
            <fieldset style="border: 1px solid; width: 85%">
                <legend>Informações do Material</legend>
                <table>
                    <tr>
                        <td>Id</td>
                        <td><input type="text" id="id" name="id" value="${result.rows[0].id}" readonly="readonly"/></td>
                    </tr>
                    <tr>
                        <td>Descrição<span class="asterisco">*</span></td>
                        <td><input type="text" id="descricao" name="descricao" ${habilitaEdicao} value="${result.rows[0].descricao}"/></td>
                    </tr>
                    <tr>
                        <td>Tempo de Decomposição<span class="asterisco">*</span></td>
                        <td><input type="text" id="tempoDeconposicao" name="tempoDecomposicao" ${habilitaEdicao} value="${result.rows[0].tempo_decomposicao}"/></td>
                    </tr>
                    <tr>
                        <td>Tóxico</td>
                        <td>
                            <input type="checkbox" id="toxico" 
                                   name="toxico"
                                   ${habilitaEdicao} 
                                   ${checkedToxico} 
                            />
                        </td>
                    </tr>
                    <tr>
                        <td>Tipo<span class="asterisco">*</span></td>
                        <td><input type="text" name="tipo" ${habilitaEdicao} value="${result.rows[0].tipo}"/></td>
                    </tr>
                    <tr>
                        <td>Observações</td>
                        <td>
                            <textarea rows="3"  
                                      name="observacoes" 
                                      style="overflow:auto;"
                                      ${habilitaEdicao} 
                            >${result.rows[0].descricao}</textarea>
                        </td>
                    </tr>
                    <tr>
                    <c:if test="${operacao=='exclui'}">
                        <td>Confirma Exclusão?</td>
                        <td>
                            <button name="confExclui" value="sim">Sim</button>
                            <button name="confExclui" value="nao">Não</button>
                        </td>
                    </c:if>
                    <c:if test="${operacao=='insere'||operacao=='altera'}">
                        <td></td>
                        <td>
                            <button>${textoBotao}</button>
                        </td>
                    </c:if>
                    </tr>
                </table>
            </fieldset>
        </form>
<span class="asterisco">Observação: Os campos marcados com asterisco são de preenchimento obrigatório.</span>


    </body>
</html>
